#pragma once

#include "../base/eec/mutex.hpp"
#include <functional>

namespace base {

template<typename T>
class HSingleton
{
public:
	static T& instance() {
		if (NULL == instance_) {
			base::eec::lock_guard<base::eec::mutex> l_lock_guard(lock_);
			if (NULL == instance_) {
				instance_ = new T();
			}
		}
		return *instance_;
	}

private:
	static T* instance_;
	static base::eec::mutex lock_;
};

template<typename T>
T* HSingleton<T>::instance_ = NULL;

template<typename T>
base::eec::mutex HSingleton<T>::lock_;

template<typename T>
class HSingletonEx {
public:
    static T& instance() {
        static T instance_;
        return instance_;
    }
};

/***********************************************************************/
} // namespace base
